SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE dbo.[DnnProduct_CDS_DistributionLogList]
	@AssetID int,
	@DistributorID varchar(50),
	@SortExpression varchar(50)
AS
BEGIN
	SET NOCOUNT ON;

	DECLARE @SQLString NVARCHAR(1000)
	DECLARE @ParmDefinition NVARCHAR(100)

	/* Build the SQL string once.*/
	SET @SQLString = N'SELECT D.[ID], D.AssetID, D.EntryDate, D.Username, D.ResponseStatus, D.Data FROM [DnnProduct_CDS_DistributionLog] D JOIN [DnnProduct_CDS_Assets] A ON D.AssetID = A.[ID] where'

	SET @SQLString = @SQLString + N' A.DistributorID = @DistributorID'
	SET @SQLString = @SQLString + N' AND D.AssetID = @AssetID'
	SET @SQLString = @SQLString + N' ORDER BY '+ @SortExpression

	SET @ParmDefinition = N'@AssetID int, @DistributorID varchar(50)'
	EXECUTE sp_executesql @SQLString, @ParmDefinition, @AssetID, @DistributorID
END
GO
